package com.yznu.dlm.mvp.Model;

import com.yznu.dlm.mvp.Presenter.IMainPresenter;
import com.yznu.dlm.mvp.Service.NewsService;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

public class NewsModel {
    IMainPresenter mIMainPresenter;

    public NewsModel(IMainPresenter iMainPresenter) {
        this.mIMainPresenter = iMainPresenter;
    }

    public void loadData() {
        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl("http://www.tngou.net")
                .addConverterFactory(GsonConverterFactory.create())
                .build();

        NewsService newsService = retrofit.create(NewsService.class);
        Call<Tngou> call = newsService.getNews(0, 1, 20);
        call.enqueue(new Callback<Tngou>() {
            @Override
            public void onResponse(Call<Tngou> call, Response<Tngou> response) {
                mIMainPresenter.loadDataSuccess(response.body());
            }

            @Override
            public void onFailure(Call<Tngou> call, Throwable t) {
                t.printStackTrace();
            }
        });
    }
}
